#pragma once
#include "gloox.h"
#include "client.h"
#include "connectionlistener.h"
#include "registration.h"
#include "loghandler.h"
#include <string>
using namespace std;

namespace gloox
{
class RegResultHandler
{
public:
	RegResultHandler() {}
	virtual ~RegResultHandler(){}
	virtual void handleRegistrationResult(const string& username, const string& password, RegistrationResult result) = NULL;
	virtual void handleAlreadyRegistered(const string& username) = NULL;
};

class RegHandler: public RegistrationHandler, ConnectionListener
{
public:
	RegHandler(RegResultHandler* regResult);
	~RegHandler(void);
	void start(const RegistrationFields& regFields, string& server, LogHandler* logHandler=NULL);
	const RegistrationFields& getRegFields() { return m_regFields; }
public:
	 virtual void onConnect();
	 virtual void onDisconnect(ConnectionError e);
	 virtual bool onTLSConnect(const CertInfo& info);
	 virtual void handleRegistrationFields(const JID& from, int fields, std::string instructions);
	 virtual void handleRegistrationResult(const JID& from, RegistrationResult result);
	 virtual void handleAlreadyRegistered(const JID& from);
	 virtual void handleDataForm(const JID& from, const DataForm& form);
	 virtual void handleOOB(const JID& from, const OOB& oob);
protected:
	static unsigned int WINAPI registerThread(void* pvoid);
	void cleanup();
protected:
	Client*					m_client;
	Registration*			m_reg;
	RegResultHandler*		m_regResult;
	RegistrationFields		m_regFields;
	
};

}